/*
 * @Author: your name
 * @Date: 2020-08-11 21:54:14
 * @LastEditTime: 2020-08-11 22:17:13
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \day01\traning\test04\main.go
 */
/*
你有50枚金币，需要分配给以下几个人：Matthew,Sarah,Augustus,Heidi,Emilie,Peter,Giana,Adriano,Aaron,Elizabeth。
分配规则如下：
a. 名字中每包含1个'e'或'E'分1枚金币
b. 名字中每包含1个'i'或'I'分2枚金币
c. 名字中每包含1个'o'或'O'分3枚金币
d: 名字中每包含1个'u'或'U'分4枚金币
写一个程序，计算每个用户分到多少金币，以及最后剩余多少金币？
程序结构如下，请实现 ‘dispatchCoin’ 函数
*/
package main

import (
	"fmt"
	"strings"
)

var (
	coins = 50
	users = []string{
		"Matthew", "Sarah", "Augustus", "Heidi", "Emilie", "Peter", "Giana", "Adriano", "Aaron", "Elizabeth",
	}
	distribution = make(map[string]int, len(users))
)

func calc(v, re string) int {
	count := strings.Count(v, re)
	if count > 0 {
		return count
	}
	return strings.Count(v, strings.ToUpper(re))

}

func dispatchCoin() int {
	count := 0
	for _, v := range users {
		sum := 0
		if sum < coins {
			switch {
			case strings.Contains(v, "e") || strings.Contains(v, "E"):
				sum += 1 * calc(v, "e")
				fallthrough
			case strings.Contains(v, "i") || strings.Contains(v, "I"):
				sum += 2 * calc(v, "i")
				fallthrough
			case strings.Contains(v, "o") || strings.Contains(v, "O"):
				sum += 3 * calc(v, "o")
				fallthrough
			case strings.Contains(v, "u") || strings.Contains(v, "U"):
				sum += 4 * calc(v, "u")
			}
			distribution[v] = sum
			count += sum
		} else {
			return 0
		}
		fmt.Printf("用户：%s 分到了 %d \n", v, sum)
	}
	return coins - count

}

func main() {
	left := dispatchCoin()
	fmt.Println("剩下：", left)
}
